package org.elec.mac.service;


import org.elec.mac.entity.SMachineTech;
import org.elec.mac.mapper.SMachineTechMapper;
import org.elec.mac.page.PageList;
import org.elec.mac.page.PageProperty;
import org.elec.mac.utils.PageUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import org.elec.mac.mapper.SMachineMapper;
import org.elec.mac.entity.SMachine;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Description:实现类
 * @author 
 * @version 1.0
 * @created 
 */
@Service
public class SMachineService extends BaseService<SMachine,SMachineMapper> implements InitializingBean {

	@Autowired
	private SMachineMapper sMachineMapper;

	@Autowired
	private SMachineTechMapper sMachineTechMapper;
	
	public void afterPropertiesSet() throws Exception {
		this.setBaseMapper(sMachineMapper);
	}

	/**
	 *
	 * @param po
	 * @param list
	 * @throws Exception
	 */
	@Transactional(rollbackFor = Exception.class)
	public void insertMachine(SMachine po, List<SMachineTech> list) throws Exception {
		sMachineMapper.insert(po);
		sMachineTechMapper.insertMachineTechBatch(list);
	}

	/**
	 *关联、分页查询
	 * @param pp
	 * @return
	 */
	public PageList<Map<String, Object>> getMachineInfoPageList(PageProperty pp) {
		int count = sMachineMapper.getMachineInfoCount(pp.getParamMap());
		int start = PageUtil.getStart(pp.getNpage(), count, pp.getNpagesize());
		int end = PageUtil.getEnd(pp.getNpage(), count, pp.getNpagesize());
		pp.putParamMap("startrow", start);
		pp.putParamMap("endrow", end);
		pp.putParamMap("pagesize", pp.getNpagesize());
		PageList<Map<String,Object>> pageList = new PageList<Map<String,Object>>(pp, count, sMachineMapper.getMachineInfoSplitList(pp.getParamMap()));
		return pageList;
	}
}
